package com.nbsaas.boot.project.rest.convert;

import com.nbsaas.boot.project.api.domain.response.ProjectResponse;
import com.nbsaas.boot.project.data.entity.Project;
import com.nbsaas.boot.rest.api.Converter;
import com.nbsaas.boot.utils.BeanDataUtils;
/**
 * 项目-实体对象转化成响应对象
 */

public class ProjectResponseConvert implements Converter<ProjectResponse, Project> {

    @Override
    public ProjectResponse convert(Project source) {
        ProjectResponse result = new ProjectResponse();
        BeanDataUtils.copyProperties(source, result);
        if (source.getCreator() != null) {
            result.setCreator(source.getCreator().getId());
        }
        if (source.getCatalog() != null) {
            result.setCatalog(source.getCatalog().getId());
        }

        try {
            if (source.getCreator() != null) {
                result.setCreatorName(source.getCreator().getName());
            }
        } catch (Exception ignored) {
        }

        if (source.getProjectState() != null) {
            result.setProjectStateName(String.valueOf(source.getProjectState()));
        }

        try {
            if (source.getCatalog() != null) {
                result.setCatalogName(source.getCatalog().getName());
            }
        } catch (Exception ignored) {
        }

        if (source.getCharger() != null) {
            result.setCharger(source.getCharger().getId());
        }
        if (source.getStoreState() != null) {
            result.setStoreStateName(String.valueOf(source.getStoreState()));
        }
        return result;
    }

}

